CXXFLAGS := -std=c++14                      \
            -fdiagnostics-color=always      \
            -Wl,--copy-dt-needed-entries    \
			-O3

ASCEND_DIR = /usr/local/Ascend/ascend-toolkit/latest

HCCL_INC_DIR = ${ASCEND_DIR}/include
HCCL_LIB_DIR = ${ASCEND_DIR}/lib64

ACL_INC_DIR = ${ASCEND_DIR}/include
ACL_LIB_DIR = ${ASCEND_DIR}/lib64

MPI_INC_DIR = ${MPI_HOME}/include
MPI_LIB_DIR = ${MPI_HOME}/lib

LIBS = -L$(HCCL_LIB_DIR) -lhccl     \
       -L$(ACL_LIB_DIR)  -lascendcl \
       -L$(MPI_LIB_DIR)  -lmpi

INCLUDEDIRS = -I$(HCCL_INC_DIR)     \
              -I$(ACL_INC_DIR)      \
              -I$(MPI_INC_DIR)

all: main perf-hccl-parallel perf-single-stream test-multi-stream

main:
	@mkdir -p ./bin
	g++ $(CXXFLAGS) ./main.cc $(INCLUDEDIRS) -o ./bin/main $(LIBS)

perf-hccl-parallel:
	@mkdir -p ./bin
	/home/sxzhang/opt/hmpi/mpic++ $(CXXFLAGS) perf-hccl-parallel.cc $(INCLUDEDIRS) -o ./bin/perf-hccl-parallel $(LIBS) -lnuma

perf-mpi-h2d-copy:
	@mkdir -p ./bin
	${MPI_HOME}/bin/mpic++ $(CXXFLAGS) perf-mpi-h2d-copy.cc $(INCLUDEDIRS) -o ./bin/perf-mpi-h2d-copy $(LIBS) -lnuma

perf-mpi-h2d-copy1:
	@mkdir -p ./bin
	${MPI_HOME}/bin/mpic++ $(CXXFLAGS) perf-mpi-h2d-copy1.cc -fopenmp $(INCLUDEDIRS) -o ./bin/perf-mpi-h2d-copy1 $(LIBS) -lnuma

perf-mpi-shared-memory:
	@mkdir -p ./bin
	${MPI_HOME}/bin/mpic++ $(CXXFLAGS) perf-mpi-shared-memory.cc $(INCLUDEDIRS) -o ./bin/perf-mpi-shared-memory $(LIBS) -lnuma -fopenmp

perf-single-stream:
	@mkdir -p ./bin
	g++ $(CXXFLAGS) perf-single-stream.cc $(INCLUDEDIRS) -o ./bin/perf-single-stream $(LIBS)

test-multi-stream:
	@mkdir -p ./bin
	g++ $(CXXFLAGS) test-multi-stream.cc $(INCLUDEDIRS) -o ./bin/test-multi-stream $(LIBS)

.PHONY: clean
clean:
	rm -rf ../bin/*
